package cn._2vin.user.bingxuexiehuione.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn._2vin.admin.bean.LogBean;
import cn._2vin.admin.bean.SysModule;
import cn._2vin.admin.bean.SysRole;
import cn._2vin.admin.module.service.SysModuleService;
import cn._2vin.admin.role.persistence.SysRoleMapper;
import cn._2vin.common.bean.ActionResult;
import cn._2vin.common.controller.service.CommonService;
import cn._2vin.common.util.StringHelper;
import cn._2vin.user.bean.LianxiFood;
import cn._2vin.user.bingxuexiehuione.persistence.HomePageMeiShiMapper;
/**
 * 
 * @author liuxuewen
 * @date 2014-1-22
 */
@Service
public class HomePageMeiShiService extends CommonService {

	@Autowired
	private HomePageMeiShiMapper homePageMeiShiMapper;
	@Autowired
	private SysRoleMapper sysRoleMapper;
	@Autowired
	private SysModuleService sysModuleService;
	/**
	 * 根据条件查找出所有权限角色列表
	 * @param bean
	 * @return
	 */
	public List<LianxiFood> queryList(LianxiFood bean){
		return homePageMeiShiMapper.queryList(bean);
	}
	public List<LianxiFood> selectlianxiFooduser(LianxiFood bean){
		return homePageMeiShiMapper.selectlianxiFooduser(bean);
		
	}
	/**
	 * 列出权限角色列表
	 * 
	 * @param bean
	 * @return
	 */
	public List<LianxiFood> selectPageSysRole(LianxiFood bean) {
		return homePageMeiShiMapper.selectPageSysRole(bean);
	}
	public List<LianxiFood> selectUserSign(){
		return homePageMeiShiMapper.selectUserSign();
		
	}
	public List<LianxiFood> selectLianxiFood(){
		return homePageMeiShiMapper.selectLianxiFood();
		
	}

	public List<LianxiFood> listlianxifood(String key) {
        try {
        	return homePageMeiShiMapper.listlianxifood(key);
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}
	public List<LianxiFood> selectlistlianxifood(String userclassname){
		return homePageMeiShiMapper.selectlistlianxifood(userclassname);
		
	}
	
	
	
	public List<LianxiFood> selectusername(String username){
		return homePageMeiShiMapper.selectusername(username);
		
	}


	/**
	 * id查询
	 * 
	 * @param id
	 * @return
	 */
	public List<LianxiFood> queryPrimaryKey(String userclassid) {
		return homePageMeiShiMapper.queryPrimaryKey(userclassid);
	}
	
	
	
	public LianxiFood queryLianxifood(String userclassid) {
		return homePageMeiShiMapper.queryLianxifood(userclassid);
	}
	

	/**
	 * 添加权限角色，添加之后插入权限角色中间表
	 * @param bean
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insert(LianxiFood bean) {
		
		homePageMeiShiMapper.insert(bean);
	}
	
	
	/**
	 * 修改系统模块
	 * @param bean
	 */
	@Transactional(rollbackFor = Exception.class)
	public void update(LianxiFood bean,LianxiFood oldBean) {
		homePageMeiShiMapper.update(oldBean);

	}

	/**
	 * 批量删除用户
	 * @param ids
	 * @return ActionResult 返回的code = 0，正常，code < 0，异常
	 * @throws Exception 
	 */
	@Transactional(rollbackFor = Exception.class)
	public ActionResult batchDelete(String ids) throws Exception {
		/*操作日志类*/
		LogBean logBean = new LogBean(); 
		ActionResult result = new ActionResult();
		result.setCode(0);
		String[] idList = ids.split(",");
		SysRole bean = null;
		for(String id : idList){
			bean = sysRoleMapper.queryPrimaryKey(id);
			if(null == bean){
				result.setCode(-1);
				throw new Exception();
			}else{
				/**
				 * 插入日志
				 */
				logBean.setTitle("删除权限角色");
				logBean.setAction("删除权限角色信息["+bean.toString()+"]");
				
				sysRoleMapper.delete(id);
				
				insertLog(logBean);
			}
		}
		return result;
	}

}
